import './utils/logger.js';
import {chadanJob, refreshToken} from './jobs/chadan.js';
import schedule from "node-schedule";
// import config from "./config.js";
import { sleep } from "./utils/index.js";

await refreshToken();

async function job() {
  let count = 50;
  for (let i = 0; i < count; i++) {
    setTimeout(() => {
      chadanJob().catch(console.error);
    },i * 20)
  }
}

schedule.scheduleJob('9,19,29,39,49,59 * * * * ?', async function(){
  await sleep(500);
  try {
    await job();
    await sleep(5 * 1000);
    await refreshToken();
  }catch (e) {
    console.error(e.message);
  }
});
